package day27;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Server1 {
    public static void main(String[] args) throws IOException {
        //1.创建服务端对象
        ServerSocket serverSocket = new ServerSocket(9999);
        while (true) {
            //2.等待客户端连接
            Socket client = serverSocket.accept();
            System.out.println(client.getInetAddress()+"连接成功");
            //3.获取输入输出流
            InputStream is = client.getInputStream();//负责读取客户端读取的数据
            OutputStream os = client.getOutputStream();//负责向客户端写入数据
            os.write("你好，我是服务端\n".getBytes());

            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            System.out.println(client.getInetAddress()+"客户端:"+br.readLine());//bug  读取一行
        }
    }
}
